<?php 
if(!session_is_registered("username") && $currPage != "signin" && $currPage != "register" && $currPage != "index")
{
$url = "signin.php";
$url .= (basename($_SERVER['PHP_SELF']) != $url) ? "?redirect=" . basename($_SERVER['PHP_SELF']) : "";
header("location:" . $url);
}

$db_host="mysql-user.cse.msu.edu"; // Host name
$db_user="hewittry"; // Mysql username
$db_pword="A39777266"; // Mysql password
$db_name="hewittry"; // Database name

mysql_connect("$db_host", "$db_user", "$db_pword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="variant-classic.css" title="Variant Classic" media="screen,projection" />
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
	<title>CSE 480 - The Transportation Station</title>
</head>

<body>
<div id="top"><div class="inner">

	<div id="topleft">
		<h1><a href="index.php">The Transportation Station</a></h1>
		<p>Helping you find the (second-hand) car of your dreams</p>
	</div>

	<div id="topright">
		<p>
			<?php    
				if(session_is_registered("username")) 
				{ 
					echo '<a class="headerlink" href="manageAccount.php">', $_SESSION["username"], '</a> |'; 
					echo ' <a class="headerlink" href="logout.php">Logout</a>'; 
				} 
			else
				{ 
					echo '<a class="headerlink" href="signin.php">Login</a>';
				}
			?> |
			<a class="headerlink" href="help.php">Help</a> |
			<a class="headerlink" href="manager.php">Manager</a>		
		</p>
		<?php 
			$query = "SELECT COUNT(VehicleForSale_VehicleForSaleID) AS numOfMsgs FROM Notification WHERE VehicleForSale_VehicleForSaleID IN ( SELECT VehicleForSaleID FROM VehicleForSale WHERE NonAdmins_AllUsers_LogonID = '" . $_SESSION["username"] . "');";
			$result = mysql_query($query) or die(mysql_error());
			if (mysql_num_rows($result))
			{
				$row = mysql_fetch_assoc($result);
				$cnt = $row['numOfMsgs'];
			}
			else {
				$cnt = 0;
			}
			if ($cnt) {
		?>
		<p>
			<a href="notifications.php"><i>You have <?php echo $cnt; ?> new notification(s)!</i></a>
		</p>
		<?php } ?>
	</div>
	<br class="clear" />

	<div id="mainmenu">
		<ul>
			<li <?php if ($currPage == "index" || $currPage == "signin") { echo 'class="current_page_item"'; } ?>><a href="index.php">Home</a></li>
			<li <?php if ($currPage == "post") { echo 'class="current_page_item"'; } ?>><a href="postAnnouncement.php">Post Announcement</a></li>
			<li <?php if ($currPage == "search") { echo 'class="current_page_item"'; } ?>><a href="searchAnnouncements.php">View Announcements</a></li>
			<li <?php if ($currPage == "searchCars") { echo 'class="current_page_item"'; } ?>><a href="searchCars.php">Search Announcements</a></li>
			<li <?php if ($currPage == "manage") { echo 'class="current_page_item"'; } ?>><a href="manageAccount.php">Manage Account</a></li>
		</ul>
	</div>
	<br class="clear" />
</div></div>

<div id="wrap"><div class="inner">
